package com.itgungnir.diyshuo.fragment.fenlei_fragment;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.widget.RadioGroup;

import com.itgungnir.diyshuo.activity.R;
import com.itgungnir.diyshuo.base.BaseFragment;
import com.itgungnir.diyshuo.fragment.fenlei_items_fragment.Fenlei_DanpinFragment;
import com.itgungnir.diyshuo.fragment.fenlei_items_fragment.Fenlei_ZhinanFragment;

/**
 * 分类页面中对应MVP模式中Model层的类
 */
public class FenleiModel implements FenleiContract.Model {
    private Fragment[] fragments = {new Fenlei_ZhinanFragment(), new Fenlei_DanpinFragment()};

    @Override
    public void initDataForViewPager(BaseFragment fragment, ViewPager vp) {
        vp.setAdapter(new FragmentPagerAdapter(fragment.getChildFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return fragments[position];
            }

            @Override
            public int getCount() {
                return fragments.length;
            }
        });
    }

    @Override
    public void onRadioGroupCheckedChangeListener(int checkedId, ViewPager vp) {
        switch (checkedId) {
            case R.id.find_fenleimain_rb_zhinan:
                vp.setCurrentItem(0);
                break;
            case R.id.find_fenleimain_rb_danpin:
                vp.setCurrentItem(1);
                break;
        }
    }

    @Override
    public void onViewPagerPageChangedListener(int position, RadioGroup rg) {
        System.out.println("---" + position);
        switch (position) {
            case 0:
                rg.check(R.id.find_fenleimain_rb_zhinan);
                break;
            case 1:
                rg.check(R.id.find_fenleimain_rb_danpin);
                break;
        }
    }

    @Override
    public void onSearchClickedListener() {
    }
}